package cn.iocoder.yudao.framework.dict.config;

import cn.iocoder.yudao.framework.common.biz.dict.DictDataCommonApi;
import cn.iocoder.yudao.framework.dict.core.DictFrameworkUtils;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;

@AutoConfiguration
public class YudaoDictAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public DictDataCommonApi dictDataCommonApi() {
        return dictType -> {
            throw new UnsupportedOperationException("无效的 Bean(%s)，请检查是否引入了基建模块并实现了该接口！".formatted(DictDataCommonApi.class.getName()));
        };
    }

    @Bean
    @SuppressWarnings("InstantiationOfUtilityClass")
    public DictFrameworkUtils dictUtils(DictDataCommonApi dictDataApi) {
        DictFrameworkUtils.init(dictDataApi);
        return new DictFrameworkUtils();
    }

}
